//var ws = new ReconnectingWebSocket("ws://123.56.199.100:8087/");
var ws = new ReconnectingWebSocket("ws://127.0.0.1:8089/");
//var ws = new ReconnectingWebSocket("ws://10.2.9.96:8087/");

ws.onopen = function() {
    console.log("Opened");
};

ws.onmessage = function (evt) {
    console.log(evt);
    console.log(evt.data);
};

ws.onconnecting = function (e) {
    console.log(e);
    // 因为没有权限, websocket即将关闭
    if (e.code == 4001) {
        // alert(e.reason);
        console.log("4001");
    }
};

ws.onclose = function (e) {
    console.log(e);
    console.log("Closed");
};

ws.onerror = function(err) {
    console.log("Error: " + err);
};

$(document).ready(function(){
    $('#send').on('click',function(){
        console.log("send");
        ws.send("I'm client2");
    });
});
